package com.lanou3g.k12.service.impl;

import com.github.pagehelper.PageHelper;
import com.lanou3g.k12.entity.Supporter;
import com.lanou3g.k12.mapper.SupporterMapper;
import com.lanou3g.k12.service.SupporterService;
import com.lanou3g.k12.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class SupporterServiceImpl implements SupporterService {
    @Autowired
    private SupporterMapper supporterMapper;


    @Override
    public List<Supporter> findAll(Integer page, Integer size) {
//        PageHelper.startPage(page,size);
        List<Supporter> supporterList= supporterMapper.findAll();
        return supporterList;
    }

    @Override
    public String insert(Supporter supporter) throws Exception {
        supporter.setCreateTime(new Date());
        supporter.setUpdateTime(new Date());
        String uuid = UUID.randomUUID().toString().substring(0, 6);
        String password = MD5Utils.md5(uuid, "password");
        supporter.setPassword(password);
        supporterMapper.insert(supporter);
        return uuid;

    }

    @Override
    public void deleteSomeSupporter(Long[] ids) {
        supporterMapper.deleteSomeSupporter(ids);
    }

    @Override
    public void deleteById(Integer id) {
        supporterMapper.deleteById(id);
    }

    @Override
    public void updateById(Supporter supporter) {
        supporterMapper.updateById(supporter);
    }


    @Override
    public String resetPassword(Supporter supporter) throws Exception {
        String uuid = UUID.randomUUID().toString().substring(0,6);
        String password1 = MD5Utils.md5(uuid, "password");
        supporter.setPassword(password1);
        System.out.println(supporter);
        supporterMapper.resetPassword(supporter);
        return uuid;
    }

}


